<template>
  <a-modal
    title="新增用户表"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">



        <a-form-item
          label="账号(手机号)"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入账号(手机号)" v-decorator="['account', {rules: [{required: true, message: '请输入账号(手机号)！'}]}]" />
        </a-form-item>

        <a-form-item
          label="密码"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入密码" v-decorator="['password', {rules: [{required: true, message: '请输入密码！'}]}]" />
        </a-form-item>

        <a-form-item
          label="昵称"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入昵称" v-decorator="['nickName', {rules: [{required: true, message: '请输入昵称！'}]}]" />
        </a-form-item>

        <a-form-item
          label="姓名"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入姓名" v-decorator="['name', {rules: [{required: true, message: '请输入姓名！'}]}]" />
        </a-form-item>

        <a-form-item
          label="简介"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入简介" v-decorator="['introduce', {rules: [{required: true, message: '请输入简介！'}]}]" />
        </a-form-item>

        <a-form-item
          label="头像"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入头像" v-decorator="['avatar', {rules: [{required: true, message: '请输入头像！'}]}]" />
        </a-form-item>

        <a-form-item
          label="生日"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入生日" v-decorator="['birthday', {rules: [{required: true, message: '请输入生日！'}]}]" />
        </a-form-item>

        <a-form-item
          label="性别(字典 1男 2女 3未知)"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入性别(字典 1男 2女 3未知)" v-decorator="['sex', {rules: [{required: true, message: '请输入性别(字典 1男 2女 3未知)！'}]}]" />
        </a-form-item>



      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { add } from '@/api/modular/erUser/erUserManage'

  export default {
    data() {
      return {
        labelCol: {
          xs: {span: 24},
          sm: {span: 5}
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 15}
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      add(record) {
        this.visible = true
      },
      handleSubmit() {
        const {form: {validateFields}} = this
        this.confirmLoading = true

        validateFields((errors, values) => {
          if (!errors) {
            add(values).then((res) => {
              this.confirmLoading = false
              if (res.success) {
                this.$message.success('新增成功')
                this.handleCancel()
                this.$emit('ok', values)
              } else {
                this.$message.info('新增失败：' + res.message)
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel() {
        this.form.resetFields();
        this.visible = false
      }
    }
  }
</script>
